package com.oa.desktop.news.news_label.handler;

import com.oa.commons.beans.NewsLabel;
import com.oa.commons.ov.Page;
import com.oa.desktop.news.news_label.service.INewsLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/newsLabel")
public class NewsLabelHandler{
    @Autowired
    private INewsLabelService newsLabelService;
    @RequestMapping("/queryNewsLabel.do")
    public String queryNewsLabel(@RequestParam(defaultValue = "1") int pageNum, HttpServletRequest request){
        Page<NewsLabel> page = newsLabelService.findCurrPage(pageNum);
        List<NewsLabel> list = newsLabelService.findNewsLabel();
        request.setAttribute("list",list);
        request.setAttribute("page",page);
        return "/jsp/news/newsLabelManager.jsp";
    }
    @RequestMapping("/findNewsLabelChildren.do")
    public String findNewsLabelChildren(int id,@RequestParam(defaultValue = "1") int pageNum, HttpServletRequest request){
        System.out.println(id);
        Page<NewsLabel> page = newsLabelService.findCurrPageChildren(id,pageNum);
        List<NewsLabel> list = newsLabelService.findNewsLabel();
        request.setAttribute("pid",id);
        request.setAttribute("list",list);
        request.setAttribute("page",page);
        List<NewsLabel> data = page.getDatas();
        for (int i = 0; i < data.size(); i++) {
            System.out.println(data.get(i));
        }
        System.out.println(page.getDatas().get(0).getName());
        return "/jsp/news/newsLabelChildren.jsp";
    }
    @RequestMapping("/deleteNewsLabel.do")
    public String deleteNewsLabel(int id){
        newsLabelService.deleteNewsLabel(id);
        return "/newsLabel/queryNewsLabel.do";
    }
    @RequestMapping("/addNewsLabelFind.do")
    public String addNewsLabel(HttpServletRequest request){
        List<NewsLabel> list = newsLabelService.findNewsLabel();
        request.setAttribute("list",list);
        return "/jsp/news/addNewsLabel.jsp";
    }
    @RequestMapping("addNewsLabel.do")
    public String addNewsLabel(NewsLabel newsLabel){

        System.out.println(newsLabel.getName());
        System.out.println(newsLabel.getContent());
        newsLabelService.addNewsLabel(newsLabel);
        return "/jsp/news/addNewsLabel.jsp";
    }
    @RequestMapping("/findUpdateNewsLabel.do")
    public String findUpdateNewsLabel(int id,HttpServletRequest request){
        List<NewsLabel> list = newsLabelService.findNewsLabelById(id);
        List<NewsLabel> lists = newsLabelService.findNewsLabel();
        request.setAttribute("list",list);
        request.setAttribute("lists",lists);
        return "/jsp/news/updateNewsLabel.jsp";
    }
    @RequestMapping("/updateNewsLabel.do")
    public String updateNewsLabel(NewsLabel newsLabel,@RequestParam int id){
        newsLabelService.updateNewsLabel(newsLabel,id);
        return "/newsLabel/findUpdateNewsLabel.do";
    }

}
